<template>
    <!--
    https://www.cnblogs.com/yingzi1028/p/9273185.html
    -->
    <div class="login_container">
        <div class="login_box">
            <!-- 头像 -->
            <div class="avatar_box">
                <img src="../assets/logo.png" alt="">
            </div>
            <!-- 登录表单 -->
            <el-form ref="form" :model="loginInfo" label-width="0" class="login_form">
                <el-form-item>
                    <el-input v-model="loginInfo.username"
                              prefix-icon="iconfont icon-user"
                              placeholder="请输入用户名">
                    </el-input>
                </el-form-item>                <el-form-item>
                    <el-input v-model="loginInfo.password"
                              type="password"
                              prefix-icon="iconfont icon-3702mima"
                              placeholder="请输入密码">
                    </el-input>
                </el-form-item>
                <el-row>
                    <el-col :span="14">
                        <el-form-item class="vcode_item">
                            <div><el-input v-model="loginInfo.vcode" placeholder="请输入验证码"></el-input></div>
                        </el-form-item>
                    </el-col>
                    <el-col :span="10">
                        <div class="vcode_img">
                            <img :src="imgUrl" alt="验证码" @click="initCaptcha" title="点击刷新">
                        </div>
                    </el-col>
                </el-row>
                <el-form-item class="btns">
                    <el-button style="width: 280px" type="primary" @click="loginClick">登录</el-button>
                </el-form-item>
            </el-form>

        </div>
    </div>
</template>

<script>
    export default {
        name: 'Login',
        data() {
            return {
                loginInfo: {
                    username: '',
                    password: '',
                    vcode: ''
                },
                imgUrl: ""
            }
        },
        methods: {
            loginClick () {
                console.log("loginClick");
                let url = "/base/login";
                let _this = this;
                this.postRequest(url, _this.loginInfo).then(res => {
                    console.log(res);
                });

            },
            initCaptcha() {
                let url = "/base/captcha";
                this.getRequest(url).then(res => {
                    this.imgUrl = res.data;
                });
            }
        },
        mounted () {
            this.initCaptcha();
        }
    }
</script>

<style lang="less" scoped>
    .login_container {
        background-color: #2b4b6b;
        height: 100%;
    }

    .login_box {
        width: 450px;
        height: 380px;
        background-color: #fff;
        border-radius: 3px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        .avatar_box {
            width: 130px;
            height: 130px;
            border: 1px solid #eee;
            border-radius: 50%;
            padding: 10px;
            box-shadow: 0 0 10px #ddd;
            position: absolute;
            left: 50%;
            transform: translate(-50%, -50%);
            background-color: #fff;
            img {
                width: 100%;
                height: 100%;
                border-radius: 50%;
                background-color: #eee;
            }
        }
        display: flex;
        justify-content: center;
    }

    .btns {
        display: flex;
        justify-content: center;
    }

    .login_form {
        position: absolute;
        bottom: 0;
        width: 75%;
        padding: 20px 30px;
        box-sizing: border-box;
    }

    .vcode_item {
        width: 150px;
        display: flex;
        justify-content: space-between;
    }

    .vcode_img {
        width: 100%;
        height: 40px;
        /*border: 1px #eee solid;*/
        box-sizing: border-box;
        display: flex;
        justify-content: center;
    }

</style>
